package com.nowcoder.community.event;

import com.alibaba.fastjson.JSONObject;
import com.nowcoder.community.entity.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class EventProducer {
    private KafkaTemplate kafkaTemplate;

    @Autowired
    public EventProducer(KafkaTemplate kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    //处理事件
    public void fireEvent(Event event){
        //将事件发布到指定的主题，主题空间满了咋整，删掉？
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSON(event).toString());
    }
}
